package kotan.controller._kotan.samples;

import java.util.Date;

import kotan.meta._KotanEntityMeta;
import kotan.model._KotanEntity;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.datastore.Datastore;

import com.google.appengine.api.datastore.Blob;
import com.google.appengine.api.datastore.Text;

public class CreateController extends Controller {

    @Override
    public Navigation run() throws Exception {
        _KotanEntityMeta meta = _KotanEntityMeta.get();
        _KotanEntity entity1 = new _KotanEntity();
        entity1.setKey(Datastore.createKey(meta, 1));
        entity1.setStrValue("String1");
        entity1.setBoolValue(true);
        entity1.setLongValue(400L);
        entity1.setDoubleValue(10.9);
        entity1.setDateValue(new Date());
        entity1.setTextValue(new Text("Long Long Text."));
        entity1.setBlobValue(new Blob(new byte[10]));
        _KotanEntity entity2 = new _KotanEntity();
        entity2.setKey(Datastore.createKey(meta, "x"));
        entity2.setStrValue("StringX");
        entity2.setBoolValue(false);
        entity2.setLongValue(200L);
        entity2.setDoubleValue(0.123);
        entity2.setDateValue(new Date());
        entity2.setTextValue(new Text("Long Long Text2."));
        entity2.setBlobValue(new Blob(new byte[0]));
        _KotanEntity entity3 = new _KotanEntity();
        entity3.setKey(Datastore.createKey(meta, "null"));
        Datastore.put(entity1, entity2, entity3);
        return null;
    }
}
